package com.mc.algorithm;

public class FourtyOne {
	public static void findPair(int [] a ,int key){
		int low = 0;
		int high = a.length-1;
		while(low<high){
			int sum = a[low]+a[high];
			if(sum==key){
				System.out.println(a[low]);
				System.out.println(a[high]);
				break;
			}
			else if(sum>key){
				high--;
			}
			else
				low++;
		}
	}
	public static void findSum(int key){
		int p1 = 1;
		int p2 = 2;
		int sum = p1+p2;
		
		while(p1<(key+1)/2){
			if(sum<key){
				p2++;
				
			}
			else if(sum>key){
				sum-=p1;
				p1++;
			}
			else{
				for(int i=p1;i<=p2;i++)
					System.out.println(i);
				p2++;
				sum+=p2;
			}
		}
	}
	public static void main(String[] args) {
		FourtyOne.findPair(new int[]{1,2,4,7,11,15}, 15);
	}
}
